package com.fmdj.mis.api.service.Impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fmdj.common.util.PageUtils;
import com.fmdj.mis.api.db.dao.UserDao;
import com.fmdj.mis.api.db.pojo.UserEntity;
import com.fmdj.mis.api.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public Set<String> selectUserPermissions(int userId) {
        return userDao.searchUserPermissions(userId);
    }


    @Override
    public Integer login(Map param) {
        return userDao.login(param);
    }

    @Override
    public HashMap searchUserInfo(int userId) {
        return userDao.searchUserInfo(userId);
    }

    @Override
    public PageUtils selectUserByPage(Map param) {
        //计算起始索引
        Integer page = MapUtil.getInt(param, "page");
        Integer length = MapUtil.getInt(param, "length");
        Integer start = (page - 1) * length;
        param.put("start", start);

        ArrayList<HashMap> list = userDao.searchUserByPage(param);

        long count = userDao.searchUserCount(param);

        return new PageUtils(list,count,page,length);
    }

    @Override
    public ArrayList<HashMap> searchAllUser() {
        return userDao.searchAllUser();
    }

    @Override
    public HashMap searchNameAndDept(int userId) {
        return userDao.searchNameAndDept(userId);
    }

    @Override
    public HashMap searchById(int userId) {
        return userDao.searchById(userId);
    }

    @Override
    public int insert(UserEntity user) {
        return userDao.insert(user);
    }

    @Override
    public int update(Map param) {
        return userDao.update(param);
    }

    @Override
    public int deleteUserByIds(Integer[] ids) {
        return userDao.deleteUserByIds(ids);
    }

    @Override
    public int updatePassword(Map param) {
        return userDao.updatePassword(param);
    }


}